//
//  HTMBProgressHUD.m
//  CreditCommunity
//
//  Created by maiya on 2017/10/13.
//  Copyright © 2017年 maiya. All rights reserved.
//

#import "HTMBProgressHUD.h"
#import <MBProgressHUD/MBProgressHUD.h>
@interface HTMBProgressHUD ()

//@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, strong) MBProgressHUD *hud;

@end

@implementation HTMBProgressHUD

+ (instancetype)sharedMBProgressHUD {
    static HTMBProgressHUD *_instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (void)showAddToView:(UIView *)view animated:(BOOL)animated isEnabled:(BOOL)enabled {
    dispatch_async(dispatch_get_main_queue(), ^{
        self.hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
        self.hud.userInteractionEnabled = !enabled;
        //        // 显示模式,改成customView,即显示自定义图片(mode设置,必须写在customView赋值之前)
        //        self.hud.mode = MBProgressHUDModeCustomView;
        //        //设置背景
        self.hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        [self.hud.bezelView setBackgroundColor:[UIColor blackColor]];
        self.hud.bezelView.alpha = 0.8;
        self.hud.contentColor = [UIColor whiteColor];
        //        if (self.imageView == nil) {
        //            self.imageView = [[UIImageView alloc] init];
        //            self.imageView.backgroundColor = [UIColor clearColor];
        //            //设置动画帧
        //            self.imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"jzdh1.png"],
        //                                                                       [UIImage imageNamed:@"jzdh2.png"],
        //                                                                       [UIImage imageNamed:@"jzdh3.png"],
        //                                                                       [UIImage imageNamed:@"jzdh4.png"],
        //                                                                       [UIImage imageNamed:@"jzdh5.png"],
        //                                                                       [UIImage imageNamed:@"jzdh6.png"],
        //                                                                       [UIImage imageNamed:@"jzdh7.png"],
        //                                                                       [UIImage imageNamed:@"jzdh8.png"],
        //                                                                       [UIImage imageNamed:@"jzdh9.png"],
        //                                                                       nil];
        //            //设置动画总时间
        //            self.imageView.animationDuration = 1.6;
        //            //设置重复次数,0表示不重复
        //            self.imageView.animationRepeatCount = 0;
        //        }
        //开始动画
        //        self.hud.minSize = CGSizeMake(120 * ScrenWidth, 120 * ScrenHeight);
        //        self.hud.margin = 15;
        //        self.hud.customView = self.imageView;
        //        [self.imageView startAnimating];
        // 标志:必须为YES,才可以隐藏,  隐藏的时候从父控件中移除
        self.hud.removeFromSuperViewOnHide = YES;
        self.isShowing = YES;
    });
}

#pragma mark -  删除Loading
- (void)hideForView:(UIView *)view animated:(BOOL)animated {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //        [self.imageView stopAnimating];
        
        [self.hud hideAnimated:YES];
        [self.hud removeFromSuperview];
        self.isShowing = NO;
        
    });
}


@end
